namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class TableRowFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<TableRow>()
                .DerivesFrom<CellAlignment>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("tr")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            TableRow expected = new TableRow
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xml = "<tr id='id' class='class' lang='fr' title='title'>Some text</tr>";
            TableRow actual = xml.Deserialize<TableRow>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<tr />".Deserialize<TableRow>());
        }

        [Fact]
        public void serialize()
        {
            TableRow obj = new TableRow
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xpath = "1=count(/tr[@id='id'][@class='class'][@lang='fr'][@title='title'][text()='Some text'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new TableRow());
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            TableRow expected = new TableRow
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Alignment = "left",
                Character = "x",
                CharacterOffset = "2",
                VerticalAlignment = "middle"
            };

            string xml =
                "<tr" +
                " id='id'" +
                " class='class'" +
                " lang='fr'" +
                " title='title'" +
                " align='left'" +
                " char='x'" +
                " charoff='2'" +
                " valign='middle'" +
                "/>";
            TableRow actual = new TableRow().Deserialize("tr", null, xml) as TableRow;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}